package com.taxi.driver.module.guide;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.qianxx.utils.SP;
import com.taxi.driver.R;
import com.taxi.driver.common.Application;
import com.taxi.driver.common.BaseActivity;
import com.taxi.driver.config.IConstants;
import com.taxi.driver.data.user.UserRepository;
import com.taxi.driver.module.login.LoginActivity;
import com.taxi.driver.module.main.MainActivity;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 用户向导
 */
public class GuideActivity extends BaseActivity {

    @Inject
    SP mSP;
    @Inject
    UserRepository mUserRepository;

    @BindView(R.id.view_pager)
    ViewPager mViewPager;
    int[] images;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide);
        ButterKnife.bind(this);
        Application.getAppComponent().inject(this);

        images = new int[]{R.drawable.guide01, R.drawable.guide02, R.drawable.guide03};
        mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                boolean isLastItem = (position == images.length - 1);
                return GuideItemFragment.newInstance(images[position], isLastItem);
            }

            @Override
            public int getCount() {
                return images.length;
            }
        });
    }

    public void start() {
        mSP.putBoolean(IConstants.IS_NOT_FIRST, true);
        Class clz = mUserRepository.isLogin() ? MainActivity.class : LoginActivity.class;
        startActivity(new Intent(this, clz));
        finish();
    }

}
